package me.hacklh.utils;

import java.util.Map;

public class RSATester {

    static String publicKey;
    static String privateKey;
/*

    static {
        try {
            Map<String, Object> keyMap = RSAUtils.genKeyPair();
            publicKey = RSAUtils.getPublicKey(keyMap);
            privateKey = RSAUtils.getPrivateKey(keyMap);
            System.err.println("公钥: \n\r" + publicKey);
            System.err.println("私钥： \n\r" + privateKey);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
*/

    public static void main(String[] args) throws Exception {

        String enData = "";
        String private_key = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKAiKDxq2Ly6/gBjz+c1VIjH4UQS2z2doOCMqSncwmMcMN689x7e5A7Bo8c4MOyiUOgy4fBzqZy6rScJVjbkj9kTQaw04PKQ/iCSmgIKmEIXsE2EJCBrr197VmW+yoiEB9+tdxLo1OPl20EPFai3k1a9oXi2vmwDtejsrlfomBHbAgMBAAECgYEAlRY4D8gKcexGf2ZuMfzc71voxtAnfn47QdSzyl3WPSAJ/9Y+3Wb3PSXbracLJcUZPpXg9VU6HMlQXH+83O5/XUU3IuRJxoROxMfZvRBYu4VaKbRrYA7np4SDwHzxoto/GZY9sm641rRZNoh3T/bKeUQ+zoRw6zVaSUbZVcTGb0ECQQDt+JGwK1uHAfZc6L5qHFtTBth2hmilvGfnTbyPa7bMPVUf33MLVd/jDkXlfvF0TLTS0X8oJihYKtnDSws5+S6lAkEArEPvI1nyJHIS9HtfLMt3vktYU9ijn+vTCsXhEVq5orRFhWfKpFrX6xqsAlw+b9cHWx7XRgeZzheRY5QeAEzWfwJAPQGJT9F9sFm3b9AW6JsGan2JxrDkaQCo3mpWWaoyfZ+HkBk3pANK1ymUj6YAfmEfxiAA6ikGFLw/gUpewWj5JQJAS1zA/sc3zsf1EO30OkWdUivmLXBGTQ0/W6QsDYqSUeLp0y4QEg0IDvuxKqsuSYFZ33xDk4h5uhbHbTf8VAdJgwJBAKfjRZ6L+r8Ykq43amYA3DiQbd7qW9BKJ0BpStxmSFlGaUP7huoy4OJmENcHWtxS0Q+jXc/Dz22Vyocwt9hjzh8=";
        String public_key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCgIig8ati8uv4AY8/nNVSIx+FEEts9naDgjKkp3MJjHDDevPce3uQOwaPHODDsolDoMuHwc6mcuq0nCVY25I/ZE0GsNODykP4gkpoCCphCF7BNhCQga69fe1ZlvsqIhAffrXcS6NTj5dtBDxWot5NWvaF4tr5sA7Xo7K5X6JgR2wIDAQAB";

        String source = "hello, rsa";
        byte[] data = source.getBytes();
        byte[] encodedData = RSAUtils.encryptByPublicKey(data, public_key);
        enData = Base64Utils.encode(encodedData);
        byte[] decodedData = RSAUtils.decryptByPrivateKey(Base64Utils.decode(enData), private_key);
        String target = new String(decodedData);
        System.out.println("解密后文字: \r\n" + target);
        //test();
    }


}
